package engine.util;

import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.lwjgl.BufferUtils;

public class DataUtil
{
    
    //<editor-fold defaultstate="collapsed" desc="Singleton">
    private static DataUtil singleton;
    
    public static DataUtil get()
    {
        if (singleton == null)
        {
            singleton = new DataUtil();
        }
        return singleton;
    }
    //</editor-fold>
    
    
    private DataUtil()
    {
    }
    
    public String formatFloat(float input)
    {
        return String.format("%.4f", input);
    }
    
    public ByteBuffer asByteBuffer(byte[] values)
    {
        ByteBuffer buffer = BufferUtils.createByteBuffer(values.length);
        buffer.put(values);
        buffer.flip();
        return buffer;
    }
    
    public FloatBuffer asFloatBuffer(float[] data)
    {
        FloatBuffer buffer = BufferUtils.createFloatBuffer(data.length);
        buffer.put(data);
        buffer.flip();
        return buffer;
    }
    
    public FloatBuffer reserveDataFloat(int size)
    {
        FloatBuffer data = BufferUtils.createFloatBuffer(size);
        return data;
    }
    
    public IntBuffer reserveDataInt(int size)
    {
        IntBuffer data = BufferUtils.createIntBuffer(size);
        return data;
    }
    
}
